package com.shihb.behavioralpatterns.mementopattern;

/**
 *Description:
 *Version:1.0.0
 *@author shihb
 *@date 2020/7/31 21:14
 */
public class GameRole {
  private int ap;
  private int defense;
  private String name;


  public GameRole(String name) {
    this.name = name;
    ap=0;
    defense=0;
  }

  public void setName(String name) {
    this.name = name;
  }

  public String getName() {
    return name;
  }

  public int getAp() {
    return ap;
  }

  public void setAp(int ap) {
    this.ap = ap;
  }

  public int getDefense() {
    return defense;
  }

  public void setDefense(int defense) {
    this.defense = defense;
  }
  public Memento saveState(){
    return new Memento(ap,defense);
  }
  public void recover(Memento memento){
    this.ap=memento.getAp();
    this.defense=memento.getDefense();
  }

  public void showState(){
    System.out.println(name+" 当前攻击力:"+ap+" 当前防御力:"+defense);
  }
}
